package com.larry.spark.rdd.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object RDD_Oper_sortByKey {

  def main(args: Array[String]): Unit = {
    //TODO  使用spark sortByKey

    val conf = new SparkConf().setMaster("local[*]").setAppName("rdd")
    val sc = new SparkContext(conf)

    val rdd = sc.makeRDD(
      List(("a",2),("a",1),("c",3),("b",4))
    )
    //(a,2)
    //(a,1)
    //(b,4)
    //(c,3)
    //按照key排序
    val rdd1: RDD[(String, Int)] = rdd.sortByKey()

    rdd1.collect().foreach(println)
 
    sc.stop()
  }
}
